﻿using Coldairarrow.Business.Base;
using Coldairarrow.Entity.Base;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base
{
    [Route("/Base/[controller]/[action]")]
    public class Base_RegionController : BaseApiController
    {
        #region DI

        public Base_RegionController(IBase_RegionBusiness base_RegionBus)
        {
            _base_RegionBus = base_RegionBus;
        }

        IBase_RegionBusiness _base_RegionBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<Base_Region>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _base_RegionBus.GetDataListAsync(input);
        }
        /// <summary>
        /// 获取省市区信息
        /// </summary>
        /// <param name="Pid">父级ID</param>
        /// <param name="Deep">层级</param>
        /// <returns></returns>
        public async Task<List<Base_Region>> GetAddressListAsync(string Pid, string Deep)
        {
            return await _base_RegionBus.GetAddressListAsync(Pid, Deep);
        }

        [HttpPost]
        public async Task<List<Base_RegionTreeDTO>> GetTreeDataList(Base_RegionTreeInputDTO input)
        {
            input.selectable = true;
            return await _base_RegionBus.GetTreeDataListAsync(input);
        }

        [HttpPost]
        public async Task<Base_Region> GetTheData(IdInputDTO input)
        {
            return await _base_RegionBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(Base_Region data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _base_RegionBus.AddDataAsync(data);
            }
            else
            {
                await _base_RegionBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _base_RegionBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}